#! /bin/bash

#title           :ymy_ssh-keygen.sh
#description     :This script will create a yad dialog generating ssh-keys
#author		     :frimo
#date            :2020-05-23
#version         :0.1
#usage		     :ymy_ssh-keygen.sh
#notes           :This script should enable to generate ssh keys by gui
#    _    
# (///)(/ 
# /    /  

# create yad gui
dialog=$(yad --width=640 --title="yad my ssh-keygen" \
--center \
--text="Configure your SSH Key:" \
--image="../icon/ymy_64.png" \
--form \
--field="Filename" \
--field="Passphrase":H \
--field="Algorithm":CB \
"" "" 'rsa!dsa!ecdsa!ed25519')

# get status of yad dialog
status=$?

# quit application if status is 0
[[ $status -eq 1 ]] && exit 0

# get values from yad dialog
filename=$(echo $dialog | awk 'BEGIN {FS="|" } { print $1 }')
passphrase=$(echo $dialog | awk 'BEGIN {FS="|" } { print $2 }')
algorithm=$(echo $dialog | awk 'BEGIN {FS="|" } { print $3 }')

# print created bash command
echo "ssh-keygen -f ~/.ssh/$filename -t $algorithm -q -N $passphrase"

# execute created bash command
ssh-keygen -f ~/.ssh/$filename -t $algorithm -q -N $passphrase

# exit application
exit 0
